package com.visionet.school.app.web.repository.member.impl;

import org.springframework.jdbc.core.JdbcTemplate;
import com.visionet.school.app.web.entity.vo.MemberVo;
import org.springframework.jdbc.core.RowMapper;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by leon on 2017/5/5.


 */
public class MemberRelRepositoryImpl {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public List<MemberVo> AllfamilyInfo(String studentId){
        StringBuffer sql = new StringBuffer();
        sql.append("select member_name,rel_type,m.avatar_path from t_member m LEFT JOIN t_member_rel mr ON m.id=mr.rel_member_id " );
        sql.append(" WHERE mr.member_id = ? AND mr.is_deleted = '0'");
        List<Object> params = new ArrayList<>();
        params.add(studentId);
        List<MemberVo> list = jdbcTemplate.query(sql.toString(), params.toArray(),new RowMapper<MemberVo>() {
            MemberVo entity=new MemberVo();
            @Override
            public MemberVo mapRow(ResultSet rs, int rowNum) throws SQLException {
                MemberVo entity = new MemberVo();
                entity.setMemberRelType(rs.getString("rel_type"));
                entity.setMemberName(rs.getString("member_name"));
                entity.setAvatarPath(rs.getString("avatar_path"));
                return entity;
            }
        });
        return list;
    }
}
